package com.nw.controller;

import com.nw.entity.Address;
import com.nw.entity.Order;
import com.nw.entity.OrderItem;
import com.nw.service.AddressService;
import com.nw.service.OrderItemService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("order")
public class OrderItemController {
    @Resource
    OrderItemService orderItemService;
    @Resource
    AddressService addressService;
    @RequestMapping("ordercommit")

    public HashMap<String, Object> insertOrderItem(OrderItem orderItems){
        System.out.println("接受的参数为:"+orderItems);
        HashMap<String, Object> map = orderItemService.insertOrderItems(orderItems);
        orderItemService.insertOrder(orderItems);
        return map;
    }

    @RequestMapping("addresscommit")
    public HashMap<String, Object> insertOrderItem(Address address){
        System.out.println("接受的参数为:"+address );
        HashMap<String, Object> map = addressService.insertOrderAddress(address);
        return map;
    }

    @RequestMapping("shoporder")
    public HashMap<String, Object> queryOrderByReceiver(String username){
        System.out.println("查询订单接受的参数:"+username);
        HashMap<String, Object> map = orderItemService.queryOrderByReceiver(username);
        return map;
    }

    @RequestMapping("updateOrderStatus")
    public HashMap<String, Object> updateOrderStatus(Order order){
        HashMap<String, Object> map = orderItemService.updateOrderStatus(order);
        return map;
    }

    @RequestMapping("queryAllOrder")
    public HashMap<String, Object> queryAllOrder(){
        HashMap<String, Object> map = orderItemService.queryAllOrder();
        return map;
    }
}
